﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace PrattParsing
{
    [System.Diagnostics.DebuggerNonUserCode]
    public class Grammar<E>
    {
        Dictionary<string, ParseContext<E>> contexts;

        public Grammar()
        {
            contexts = new Dictionary<string, ParseContext<E>>();
            this["base"] = new ParseContext<E>();
        }

        public void AddContext(string name, ParseContext<E> context)
        {
            contexts[name] = context;
        }
        public ParseContext<E> GetContext(string name)
        {
            return contexts[name];
        }

        public ParseContext<E> this[string name]
        {
            get
            {
                return GetContext(name);
            }
            set
            {
                AddContext(name, value);
            }
        }
    }
}
